/*
 * @Author: dfh
 * @Date: 2023-12-21 11:05:03
 * @LastEditors: dfh
 * @Modified By: dfh
 * @describe: 
 */
const express = require('express');
const multer = require('multer');
const path = require('path');
const cors = require('cors');

const app = express();
//存储上传文件的目录
const uploadDir = path.join(__dirname, 'uploads');

//使用Multer中间件处理文件上传
const upload = multer({ dest: uploadDir });

//跨域处理
app.use(cors());

app.post('/upload', upload.single('file'), (req, res) => {
  if (!req.file) {
    return res.status(400).send('No files were uploaded.');
  }
  res.send('File uploaded successfully.');
})

app.listen(4000, () => {
  console.log(`Server started on http://localhost:4000 success`);
})